package com.codejam.gof.prototype.deep;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.*;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class WeeklyLog2 implements Serializable ,Cloneable{

    private Attachment2 attachment2;

    @Override
    protected WeeklyLog2 clone() throws CloneNotSupportedException {
        return (WeeklyLog2)super.clone();
    }

    public WeeklyLog2 deepClone() throws Exception{
        ByteArrayOutputStream bao = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(bao);
        oos.writeObject(this);

        //将对象取出来
        ByteArrayInputStream bi = new ByteArrayInputStream(bao.toByteArray());
        ObjectInputStream ois = new ObjectInputStream(bi);
        return (WeeklyLog2) ois.readObject();
    }

}
